using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Events;

namespace HyuFrameWork
{    
    public class UILoader
    {
        private static Dictionary<string, GameObject> UIbuffer = new Dictionary<string, GameObject>();

        private static ABService _abService;
        private static ABService AbService => _abService ??= ServiceManager.Check<ABService>();
        
        public static GameObject Load<T>() where T : UIPanel
        {
            var name = typeof(T).Name;
            if (UIbuffer.TryGetValue(name, out GameObject obj))
                return obj;
            obj = AbService.LoadRes<GameObject>("ui",name);
            UIbuffer.Add(name,obj);
            return obj;
        }

        public static void LoadAsync<T>(UnityAction<GameObject> cb)  where T : UIPanel
            =>AbService.LoadResAsync("ui", nameof(T),null,null, null,cb);
    }
}